#!/usr/bin/env bash
START_TIME=$(date +%s)
cwd=`pwd`
echo "Please Run this script on the root dir, not in scripts dir."
echo "Current dir: $cwd"

if [ -d "build" ]; then
  echo "Recreating build dir."
  rm -rf build
fi
mkdir -p build/

pushd cmd/ || exit

for i in *; do
    name="$i"
    capName="${name^}"
    echo "Building $i"
    cd "$i" || exit
    (set -x; go build -o "$cwd/build/$i")
    cd ..
done

popd || exit
ELAPSED=$(($(date +%s) - START_TIME))
echo "Build completed."
printf "elapsed: %s\n\n" "$(date -d@$ELAPSED -u +%H\ hours\ %M\ min\ %S\ sec)"